package homework_04;

/**
 * 求数组平均值，最大值，最小值
 */
public class Test_06 {
    public static void main(String[] args) {
        int[] arr = {-10,2,3,246,-100,0,5};
        int avg = arrAvg(arr);
        int max = arrMax(arr);
        int min = arrMin(arr);
        System.out.println("该数组平均值为" + avg);
        System.out.println("该数组最大值为" + max);
        System.out.println("该数组最小值为" + min);
    }

    public static int arrAvg(int[] arr){
        int sum = 0;
        int avg = 0;
        for(int i=0;i<arr.length;i++){
            sum += arr[i];
        }
        avg = sum / arr.length;
        return avg;
    }

    public static int arrMax(int[] arr){
        int max = 0;
        for(int i=0;i<arr.length;i++){
            if(max<arr[i]){
                int tmp = max;
                max = arr[i];
                arr[i] = tmp;
            }
        }
        return max;
    }

    public static int arrMin(int[] arr){
        int min = 0;
        for(int i=0;i<arr.length;i++){
            if(min>arr[i]){
                int tmp = min;
                min = arr[i];
                arr[i] = tmp;
            }
        }
        return min;
    }
}
